//
//  PhotoTableViewCell.m
//  quickDoctor
//
//  Created by zhaowei on 17/3/10.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "PhotoTableViewCell.h"

@implementation PhotoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}
#pragma mark
#pragma mark -初始化页面
- (void)setupUI {
    //添加dataLabel
    UILabel *dataLabel = [[UILabel alloc] init];
    _dataLabel = dataLabel;
    [dataLabel sizeToFit];
    [self.contentView addSubview:dataLabel];
    
    //约束
    [dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.leading.offset(60);
    }];
    
    //添加imageview
    UIImageView *imageview = [[UIImageView alloc] init];
    _photoView = imageview;
    [self.contentView addSubview:imageview];
    //约束
    [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.offset(-10);
        make.top.equalTo(dataLabel.mas_bottom).offset(10);
        make.leading.offset(50);
        make.width.height.mas_equalTo(100);
    }];
    //添加疾病类型label
    UILabel *typeLabel = [[UILabel alloc] init];
    typeLabel.text = @"疾病类型";
    typeLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:typeLabel];
    
    //约束
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageview);
        make.leading.equalTo(imageview.mas_trailing).offset(10);
        make.width.mas_equalTo(100);
    }];
    //添加baseTypeLabel
    UILabel *baseTypeLabel = [[UILabel alloc] init];
    baseTypeLabel.text = @"基本类型";
    typeLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:baseTypeLabel];
    
    //约束
    [baseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(typeLabel.mas_leading);
        make.top.equalTo(typeLabel.mas_bottom).offset(10);
        make.width.mas_equalTo(100);
    }];
    
    //添加detailTypeLabel
    UILabel *detailTypeLabel = [[UILabel alloc] init];
    _detailTypeLabel = detailTypeLabel;
    [detailTypeLabel sizeToFit];
    detailTypeLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:detailTypeLabel];
    
    //约束
    [detailTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(typeLabel);
        make.leading.equalTo(typeLabel.mas_trailing).offset(10);
    }];
    
    //添加baseDetailTypeLabel
    UILabel *baseDetailTypeLabel = [[UILabel alloc] init];
    _baseDetailTypeLabel = baseDetailTypeLabel;
    baseDetailTypeLabel.textColor = [UIColor lightGrayColor];
    [baseDetailTypeLabel sizeToFit];
    [self.contentView addSubview:baseDetailTypeLabel];
    
    //约束
    [baseDetailTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(baseTypeLabel);
        make.leading.equalTo(baseTypeLabel.mas_trailing).offset(10);
        
    }];
    
    //添加显示textView数据的label
    UILabel *textViewLabel = [[UILabel alloc] init];
    _textViewLabel = textViewLabel;
    textViewLabel.textColor = [UIColor lightGrayColor];
    [textViewLabel sizeToFit];
    [self.contentView addSubview:textViewLabel];
    
    //约束
    [textViewLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(baseTypeLabel);
        make.top.equalTo(baseTypeLabel.mas_bottom).offset(10);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    //画圆
    CGRect frame = CGRectMake(10, 10, 15, 15);
    //获取上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[UIColor whiteColor] set];
    
    CGContextFillRect(context, rect);
    
    CGContextAddEllipseInRect(context, frame);
    [[UIColor greenColor] set];
    
    //添加边框
    CGRect makeFrame = CGRectMake(5, 5, 40, 40);
    CGContextFillPath(context);
    CGContextSetLineWidth(context, 8);
    CGContextAddArc(context, makeFrame.origin.x + makeFrame.size.width/2, makeFrame.origin.y + makeFrame.size.height/2, makeFrame.size.height/2-2, 0, 2*M_PI, 0);
    CGContextDrawPath(context, kCGPathStroke);
    //画线 带动画
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 25, 45);
    CGPathAddLineToPoint(path, NULL, 25, 180);
    CGPathCloseSubpath(path);
    CGContextAddPath(context, path);
    CGContextSetLineWidth(context, 3);
    CGContextDrawPath(context, kCGPathFillStroke);
    
    
}
@end
